1
|
8 |
|
import { Controller, Get, Param, Query } from '@nestjs/common'; |
2
|
8 |
|
import { |
3
|
|
|
ApiBearerAuth, |
4
|
|
|
ApiOperation, |
5
|
|
|
ApiResponse, |
6
|
|
|
ApiTags, |
7
|
|
|
ApiParam, |
8
|
|
|
ApiQuery, |
9
|
|
|
} from '@nestjs/swagger'; |
10
|
|
|
// import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; |
11
|
8 |
|
import { ZonesService } from './zones.service'; |
12
|
8 |
|
import { ZoneFilterQueryDto } from './dto/zone-filter-query.dto'; |
13
|
|
|
import { ZoneResponse } from './types/ZoneResponse'; |
14
|
|
|
import { ZoneQuery } from './types/ZoneQuery'; |
15
|
8 |
|
import { CityName } from 'src/cities/types/city.enum'; |
16
|
|
|
|
17
|
|
|
@ApiTags('Zones') |
18
|
|
|
@Controller({ path: 'zone', version: '1' }) |
19
|
8 |
|
export class ZonesController { |
20
|
7 |
|
constructor(private readonly zonesService: ZonesService) {} |
21
|
|
|
@Get() |
22
|
|
|
// @ApiBearerAuth() |
23
|
|
|
@ApiOperation({ summary: 'Get all zones' }) |
24
|
|
|
@ApiQuery({ name: 'lat', required: false, type: Number }) |
25
|
|
|
@ApiQuery({ name: 'lon', required: false, type: Number }) |
26
|
|
|
@ApiQuery({ |
27
|
|
|
name: 'type', |
28
|
|
|
required: false, |
29
|
|
|
enum: ['parking', 'charging', 'speed'], |
30
|
|
|
}) |
31
|
|
|
@ApiQuery({ name: 'includes', required: false, enum: ['bikes'] }) |
32
|
|
|
@ApiQuery({ |
33
|
|
|
name: 'city', |
34
|
|
|
required: false, |
35
|
|
|
enum: ['Göteborg', 'Jönköping', 'Karlshamn'], |
36
|
|
|
}) |
37
|
|
|
@ApiQuery({ name: 'rad', required: false, type: Number }) |
38
|
|
|
@ApiResponse({ |
39
|
|
|
status: 200, |
40
|
|
|
description: 'List of zones', |
41
|
|
|
schema: { |
42
|
|
|
type: 'array', |
43
|
|
|
example: [ |
44
|
|
|
{ |
45
|
|
|
id: 'b1e77dd3-9fb9-4e6c-a5c6-b6fc58f59464', |
46
|
|
|
polygon: [ |
47
|
|
|
{ lat: 59.3293, lng: 18.0686 }, |
48
|
|
|
{ lat: 59.3294, lng: 18.0687 }, |
49
|
|
|
{ lat: 59.3295, lng: 18.0688 }, |
50
|
|
|
], |
51
|
|
|
type: 'speed', |
52
|
|
|
city: 'Göteborg', |
53
|
|
|
speedZone: { |
54
|
|
|
id: 'c2f88dd4-0ba9-5f7c-b5d7-c7fc59f59465', |
55
|
|
|
speedLimit: 20.5, |
56
|
|
|
}, |
57
|
|
|
}, |
58
|
|
|
{ |
59
|
|
|
id: 'd2a77ee5-0fa9-4e7c-a6d7-b7fc59f59466', |
60
|
|
|
polygon: [ |
61
|
|
|
{ lat: 59.8586, lng: 17.6389 }, |
62
|
|
|
{ lat: 59.8587, lng: 17.639 }, |
63
|
|
|
{ lat: 59.8588, lng: 17.6391 }, |
64
|
|
|
], |
65
|
|
|
type: 'parking', |
66
|
|
|
city: 'Göteborg', |
67
|
|
|
}, |
68
|
|
|
], |
69
|
|
|
}, |
70
|
|
|
}) |
71
|
|
|
@ApiResponse({ |
72
|
|
|
status: 401, |
73
|
|
|
description: 'Unauthorized. Authentication required', |
74
|
|
|
}) |
75
|
8 |
|
async getAllZones(@Query() query: ZoneFilterQueryDto): Promise<ZoneResponse> { |
76
|
7 |
|
const filters: ZoneQuery = { |
77
|
|
|
lat: query.lat ? query.lat : null, |
78
|
|
|
lon: query.lon ? query.lon : null, |
79
|
|
|
type: query.type ? (query.type.split(',') as ('parking' | 'charging' | 'speed')[]) : [], |
80
|
|
|
includes: query.includes ? (query.includes.split(',') as 'bikes'[]) : [], |
81
|
|
|
city: query.city ? (query.city.split(',') as ('Göteborg' | 'Jönköping' | 'Karlshamn')[]) : [], |
82
|
|
|
rad: query.rad ? query.rad : null, |
83
|
|
|
}; |
84
|
|
|
|
85
|
7 |
|
const zones = await this.zonesService.getZonesByFilter(filters); |
86
|
7 |
|
return { |
87
|
|
|
filters: filters, |
88
|
|
|
...zones, |
89
|
|
|
}; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
@Get('city/:cityName') |
93
|
|
|
@ApiBearerAuth() |
94
|
|
|
@ApiOperation({ summary: 'Get all zones in a specific city' }) |
95
|
|
|
@ApiResponse({ |
96
|
|
|
status: 200, |
97
|
|
|
description: 'List of zones in the specified city', |
98
|
|
|
schema: { |
99
|
|
|
type: 'array', |
100
|
|
|
example: [ |
101
|
|
|
{ |
102
|
|
|
id: 'b1e77dd3-9fb9-4e6c-a5c6-b6fc58f59464', |
103
|
|
|
polygon: [ |
104
|
|
|
{ lat: 59.3293, lng: 18.0686 }, |
105
|
|
|
{ lat: 59.3294, lng: 18.0687 }, |
106
|
|
|
{ lat: 59.3295, lng: 18.0688 }, |
107
|
|
|
], |
108
|
|
|
type: 'speed', |
109
|
|
|
city: { |
110
|
|
|
id: 'd2322ff3-a81c-4b06-b78d-1bc72b4fe459', |
111
|
|
|
name: 'Göteborg', |
112
|
|
|
latitude: null, |
113
|
|
|
longitude: null, |
114
|
|
|
createdAt: '2024-12-17T10:37:25.000Z', |
115
|
|
|
updatedAt: '2024-12-17T10:37:25.000Z', |
116
|
|
|
}, |
117
|
|
|
speedZone: { |
118
|
|
|
id: 'c2f88dd4-0ba9-5f7c-b5d7-c7fc59f59465', |
119
|
|
|
speedLimit: 20.5, |
120
|
|
|
}, |
121
|
|
|
}, |
122
|
|
|
], |
123
|
|
|
}, |
124
|
|
|
}) |
125
|
|
|
@ApiResponse({ |
126
|
|
|
status: 401, |
127
|
|
|
description: 'Unauthorized. Authentication required', |
128
|
|
|
}) |
129
|
|
|
@ApiParam({ |
130
|
|
|
name: 'cityName', |
131
|
|
|
description: 'Name of the city', |
132
|
|
|
type: 'string', |
133
|
|
|
enum: ['Göteborg', 'Jönköping', 'Karlshamn'], |
134
|
|
|
}) |
135
|
8 |
|
async getZonesByCity(@Param('cityName') cityName: CityName) { |
136
|
1 |
|
return await this.zonesService.findByCity(cityName); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|